(function () {
    let show = document.querySelector('li.show');
    let leave = document.querySelector('li.leave');
    const nkname = document.getElementsByClassName('nkname');
    let toppic = document.querySelector('img.layui-nav-img');

    // 读取session信息
    let uid = sessionStorage.getItem('uid');
    if (uid) {
        leave.style.display = 'none';
        show.style.display = 'inline-block';
    } else {
        leave.style.display = 'inline-block';
        show.style.display = 'none';
    }
    //获取当前用户信息
    axios.get('/api/user').then(function (res) {
        // console.log(res);
        const data = res.data.userinfo;
        // console.log(data);
        if (data.username) {
            nkname[0].innerHTML = data.username;
        } else {
            nkname[0].innerHTML = '克施勤德';
        }
        if (data.avater) {
            toppic.src = data.avater;
        }
    }).catch(function (error) {
        console.log(error);
    });

}
)();
